package top.caoayu.finance.tiancai.VO;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.IOException;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseDataVO<T> {
    @JsonProperty("FLAG")
    private String flag;
    @JsonProperty("DATA")
    private T data;


    public <U> U getData(TypeReference<U> dataType) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.readValue(objectMapper.writeValueAsString(data), dataType);
        } catch (JsonProcessingException e) {
            throw new RuntimeException("无法将 DATA 转换为目标类型：" + e.getMessage());
        }
    }
}
